package com.xiaoyu.lanling.feature.gift.model

import `in`.srain.cube.request.JsonData
import `in`.srain.cube.views.list.ListPositionedItemBase
import com.xiaoyu.base.app.AppContext
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.data.ConfigData
import com.xiaoyu.lanling.event.gift.GiftListEvent.NORMAL_ITEM

class Gift(position: Int, jsonData: JsonData) : ListPositionedItemBase(position) {

    val id = jsonData.optString("id")
    val type = jsonData.optString("type")
    val name = jsonData.optString("name")
    val icon = jsonData.optString("icon")
    val billId = jsonData.optString("billId")
    val fromUid = jsonData.optString("fromUid")
    val toUid = jsonData.optString("toUid")
    val coin = jsonData.optInt("coin")
    val canGive = jsonData.optBoolean("canGive")
    val giftKey = jsonData.optString("giftKey")
    var isSelected = false

    companion object {
        const val TYPE_NORMAL = "normal"
    }

    override fun getViewType(): Int {
        return NORMAL_ITEM
    }

    fun getIntimacyTitleColor(): Int {
        return AppContext.getColor(if (isSelected) R.color.colorSecondary else R.color.colorThriceText)
    }

    fun getGiftTitleColor(): Int {
        return AppContext.getColor(if (isSelected) R.color.colorSecondary else R.color.colorOnSurface)
    }

    fun getPriceDesColor(): Int {
        return AppContext.getColor(if (isSelected) R.color.colorSecondary else R.color.colorThriceText)
    }

    fun hasSvga(): Boolean {
        return getSvgaFilename().isNotEmpty()
    }

    fun getSvgaFilename(): String {
        return ConfigData.getInstance().getSvgaNormalGift(giftKey)
    }
}